package cn.tedu.online.day04;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockingQueueDemo {
    public static void main(String[] args) {
        BlockingQueue<String> queue =
                new LinkedBlockingQueue<>(5);

        Thread producer = new Thread(){
            @Override
            public void run() {

                try {
                    Thread.sleep(2000);
                    queue.put("hello");
                    System.out.println(queue);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        };
        producer.start();



        try {
            String ele = queue.take();
            System.out.println("取出"+ele);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
